﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace Acms.AcmsControls.ContentControls.FrontEnd
{
    /// <summary>
    /// Will render text as an Email link eg <a href="mailto:email@address.com">email@address.com</a>
    /// </summary>
    /// <remarks>
    /// Bassed on Text Content Control
    /// </remarks>
    public class EmailContentControlDisplay : TextContentControlDisplay
    {

        protected override void Render(HtmlTextWriter writer)
        {
            if (!base.IsEmpty)
            {
                if (!string.IsNullOrEmpty(WrapperTag))
                {
                    if (!string.IsNullOrEmpty(CssClass))
                        writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
                    writer.RenderBeginTag(WrapperTag);
                }
                else
                {
                    if (!string.IsNullOrEmpty(CssClass))
                        writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
                }
                writer.AddAttribute(HtmlTextWriterAttribute.Href, string.Format("mailto:{0}", Text.Trim()));
                writer.RenderBeginTag(HtmlTextWriterTag.A);
                writer.Write(Text);
                writer.RenderEndTag();
                if (!string.IsNullOrEmpty(WrapperTag))
                {
                    writer.RenderEndTag();
                }
            }
        }
    }
}
